unit uIteration;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TFormIteration = class(TForm)
    ButtonForTo: TButton;
    ButtonDownTo: TButton;
    ButtonWhile: TButton;
    ButtonRepeat: TButton;
    procedure ButtonForToClick(Sender: TObject);
    procedure ButtonDownToClick(Sender: TObject);
    procedure ButtonWhileClick(Sender: TObject);
    procedure ButtonRepeatClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormIteration: TFormIteration;

implementation

{$R *.dfm}

procedure TFormIteration.ButtonDownToClick(Sender: TObject);
var
  i : Integer;
  sum : Integer;
begin
  sum := 0;

  for i := 100 downto 1 do
  begin
    sum := sum + i;
  end;
  ShowMessage('100 + 99 + ... + 1 = ' + IntToStr(sum));
  ShowMessage('i = ' + IntToStr(i));
end;

procedure TFormIteration.ButtonForToClick(Sender: TObject);
var
  i : Integer;
  sum : Integer;
begin
  sum := 0;
  for i := 1 to 100 do
  begin
    sum := sum + i;
  end;
  ShowMessage('1+2+...+100 = ' + IntToStr(sum));
  ShowMessage('i = ' + IntToStr(i));
end;

procedure TFormIteration.ButtonRepeatClick(Sender: TObject);
var
  i : Integer;
  sum : Integer;
begin
  i := 1;
  sum := 0;

  repeat
    sum := sum + i;
    i := i + 1;
  until i > 100;

  ShowMessage('1+2+...+100 = ' + IntToStr(sum));
  ShowMessage('i = ' + IntToStr(i));
end;

procedure TFormIteration.ButtonWhileClick(Sender: TObject);
var
  i : Integer;
  sum : Integer;
begin
  sum := 0;
  i := 1;
  while i <= 100 do
  begin
    sum := sum + i;
    i := i + 1;
  end;
  ShowMessage('1+2+...+100 = ' + IntToStr(sum));
  ShowMessage('i = ' + IntToStr(i));
end;

end.
